package com.coincalf.wallet.web.agent;

import com.baomidou.mybatisplus.plugins.Page;
import com.coincalf.framework.http.Response;
import com.coincalf.framework.security.UserDetails;
import com.coincalf.wallet.entity.CoinWithdraw;
import com.coincalf.wallet.service.CoinWithdrawService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * <p>
 * 用户转出钱包地址 前端控制器
 * </p>
 *
 * @author qiang
 * @since 2018-04-17
 */
@RestController
@RequestMapping("/agent/coinWithdraw")
@Api(value = "用户转出钱包", description = "用户转出钱包")
public class AgentCoinWithdrawController {

    @Autowired
    private CoinWithdrawService coinWithdrawService;

    /**
     * 代理商提现
     *
     * @param page        分页参数
     * @param userName    用户名
     * @param orderId     订单号
     * @param status      状态
     * @param coinId      币种ID
     * @param parentId    上级代理商用户ID
     * @param createTime  创建时间
     * @param userDetails 当前登录用户
     * @return
     */
    @PreAuthorize("isAuthenticated()")
    @GetMapping("/outRecharge")
    @ApiOperation(value = "代理商-提现记录", httpMethod = "GET", authorizations = {@Authorization(value="Authorization")})
    @ApiImplicitParams({@ApiImplicitParam(name = "current", value = "当前页码", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "size", value = "每页大小", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "userName", value = "交易账户", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "orderId", value = "订单编号", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "提现状态", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "上级ID", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "coinId", value = "币种ID", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "创建时间", dataType = "DATE", paramType = "query")})
    public Response outRecharge(@ApiIgnore Page<CoinWithdraw> page, String userName, Integer orderId, Integer status, Integer coinId, Integer parentId, String createTime,
                                @ApiIgnore @AuthenticationPrincipal UserDetails userDetails) {
        return Response.ok(coinWithdrawService.selectOutRecharges(page, userDetails.getId(), userName, orderId, status, coinId, parentId, createTime));
    }

    /**
     * 代理商提现统计
     *
     * @param userDetails 当前登录用户
     * @return
     */
    @PreAuthorize("isAuthenticated()")
    @GetMapping("/outRechargeTotal")
    @ApiOperation(value = "代理商-提现记录统计", httpMethod = "GET", authorizations = {@Authorization(value="Authorization")})
    public Response outRechargeTotal(@ApiIgnore @AuthenticationPrincipal UserDetails userDetails) {
        return coinWithdrawService.selectOutRechargesTotal(userDetails.getId());

    }
}

